refactor of calculateInterVsIntra to reduce complexity and increase p…#47
Closed
openpaul wants to merge 2 commits into
Closed
refactor of calculateInterVsIntra to reduce complexity and increase p…#47openpaul wants to merge 2 commits into
openpaul wants to merge 2 commits into
Conversation
Author
|
Closing for now as speed differences are inconsistent and I want to test some more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
After having looked into the
pairwiseDistcode (immcantation/alakazam#133) I had a look where in scoper this code is used.I profiled the
hierarchicalClonesfunction with profvis and found that a lot of time is spend in thecalculateInterVsIntrafunction, which is where thepairwiseDistfunction is called. Noticably thepairwiseDistcall is not the most time consuming step though. From my trace I could see a lot of GC happening, but it did not directly show what calls caused this.As such I tried multiple refactors of the code and came up with this solution.
The function has the same signature as before and produces identical output to the previous version. At least as much as my tests have shown me. Tbh the old code was a bit hard to understand, but I hope I got there in the end.
I tried to not use more memory, and keep the code simple. I still have for loops but I removed many
paste0calls, which I think is the cause for the speedup.I ran a small dataset end to end with
hierarchicalClonesand see a drop from 35 seconds to 15 seconds compute time. In a larger test before the change it took 12 minutes, after only 1.1 minutes, which is a lot more than I expected. All the more reason to be critical of this PR.I checked and the clone ids between both runs are identical, but I would appreciate a solid review of the code to make sure I did not introduce any bugs.
I think this function is also used by spectral clustering, but I did no test that path yet. That's why I decided to open this PR before as a draft for now. But thought the speedup is worth sharing. And I hoped that this is interesting enough to get feedback before I continue sinking time into this.
I hope I did not overlook any hidden assumptions of the previous code. The immcantation framework is quite cool but also very complex to disentangle as an outsider :)
All the best